var http = require('http');
var url = require('url');

var login = "<div class='login-box'>" +
    "<form method='get' action='/loginSummit'>" +
    "<div>用户名：<input name='username'/></div>" +
    "<div>密码：<input name='password'/></div>" +
    "<div><button type='submit'>登录</button></div>" +
    "</form>"+
    "</div>";

var  index="<h1>主页</h1>";
http.createServer(function (request,response) {

        var urlObj = url.parse(request.url,true);

        if(urlObj.pathname=='/login'){
            response.writeHead(200,{'Content-Type':'text/html;charset=utf8'});
            response.write(login);
        }

        if(urlObj.pathname=="/loginSummit"){

           console.log(urlObj.query);

            if(urlObj.query.username=="admin"&&urlObj.query.password=="123"){
                response.writeHead(200,{'Content-Type':'text/html;charset=utf8'});
                response.write(index);
            }else{
                response.writeHead(200,{'Content-Type':'text/html;charset=utf8'});
                response.write(login);
            }


        }

        response.end();

}).listen(3000);

console.log("the server is running on port 3000");